import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

@WebServlet("/upJson")
public class UpJson extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置编码方式
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
        //获取网络输入流
        InputStream in = req.getInputStream();
        //构造高级缓冲字符流
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(in,"utf-8"));
        //读取数据
        String userJson = reader.readLine();
        System.out.println(userJson);
        resp.getWriter().write("收到数据: "+userJson);
        in.close();
        reader.close();
    }
}
